package com.hzit.security.handler;

import com.hzit.security.exption.UsernamePasswordException;
import com.hzit.util.R;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类名：
 * 作者：WF
 * 功能：处理全局异常
 */
// @ControllerAdvice
// @ResponseBody
@ControllerAdvice
public class HzitGlobalExceptionHandler {

	@ExceptionHandler(UsernamePasswordException.class)
	public String userNamePasswordExceptionHandler(UsernamePasswordException ex, Model model){
		String message = "未知异常！";
		if(ex != null){
			message = ex.getMessage();
		}
		model.addAttribute("message",message);
		return "error01";
	}
	@ExceptionHandler(UsernameNotFoundException.class)
	public String UsernameNotFoundExceptionHandler(UsernameNotFoundException ex, Model model){
		String message = "未知异常！";
		if(ex != null){
			message = ex.getMessage();
		}
		model.addAttribute("message",message);
		return "error01";
	}

}
